Computer-implemented exception handling system and method

ABSTRACT

A computer-implemented system and method for handling run-time exceptions. Source code is provided as input to a compiler. The source code includes an exception branching statement and an exception catching statement. The compiler generates machine code from the source code. During execution of the machine code, an exception occurs and execution branches to the exception catching statement in accordance with the exception branching statement.

TECHNICAL FIELD

[0001] The present invention relates generally to computer program execution flow and more particularly to computer program exception handling.

BACKGROUND

[0002] Run-time exception handling techniques currently utilize context saving operations to recover from exceptions. However, context saving operations may be performed multiple times during runtime to save the ever changing context of an executing program. The repeated context saving operations diminish the performance of an executing program. Other exception handling techniques similarly hinder performance.

SUMMARY

[0003] In accordance with the teachings disclosed herein, a computer-implemented system and method are provided for handling run-time exceptions. Source code is received by a compiler as input. The source code includes an exception branching statement and an exception catching statement. The compiler produces machine code from the source code. During execution of the machine code, an exception occurs and execution branches to the exception catching statement in accordance with the exception branching statement.

BRIEF DESCRIPTION OF THE DRAWINGS

[0004]FIG. 1 is a block diagram depicting an exception handling system;

[0005]FIG. 2 is a block diagram depicting exception handling techniques involving a C code compiling system; and

[0006]FIGS. 3 and 4 are flowcharts depicting exemplary operational steps for exception handling techniques.

DETAILED DESCRIPTION

[0007]FIG. 1 shows a computer-implemented exception handling system at 30. The system 30 allows source code 32 that contains branching and catching type exception handling operations (34, 36) to be compiled and to recover from exceptions encountered during execution. A machine code generator 38 first compiles the source code 32 along with its exception handling operations (34, 36) into machine code 40 and places it in storage 42 (e.g., a computer's hard drive or a computer server) for later execution.

[0008] The run-time exception handling operations (34, 36) include an exception branching operation 34 that records the location of recovery code contained within the exception catching operation 36. The run-time exception handling operations (34, 36) allow for the reduction or the elimination of having to continually save the context of an executing program when trapping for exceptions.

[0009] The exception handling techniques may be used with source code of many different types of higher order languages, such as C, FORTRAN, Pascal, assembly, etc. For such languages, source code may be written by a user through such editor programs as Visual C, Microsoft Fortran, Turbo Pascal, etc. The source code is stored as a file on a non-volatile storage device, such as a computer's hard drive or a server.

[0010]FIG. 2 shows an example where an exception handling generation extension 110 allows a C compiler 108 to compile C source code 104 that contains the exception handling operations (130, 132). The C compiler 108 includes compiling functionality 110 which can generate machine code 102 such that execution resumes at the EXCEPTION_LABEL( ) statement 132 no matter where in the machine code 102 the exception happens. Within the C source code 104, the exception handling operations (130, 132) may resemble the following:

[0011] ON_EXCEPTION_GOTO(label);

[0012] [code goes here that could possible cause an exception]

[0013] EXCEPTION_LABEL(label)

[0014] [recovery code to continue after an exception goes here]

[0015] The ON_EXCEPTION_GOTO( ) statement 130 is a relatively fast operation that records the location of the recovery code located at the exception label 132. When an exception happens, an exception signal handler 120 is used to allow execution to resume at the recovery code contained at the exception label 132. The exception signal handler 120 accomplishes this by placing the value stored from the exception branching functionality 130 into the PC (program counter) slot of the exception context structure that was passed to the exception signal handler 120. The exception signal handler 120 then returns, and execution continues at the exception label 132.

[0016] The ON_EXCEPTION_GOTO( ) statement 130 may be placed at any point within the source code 104. For example, the ON_EXCEPTION_GOTO( ) statement 130 may be placed in the beginning of the source code 104 in order to have exception handling techniques available from the execution's start. The exception-related statements (130 and 132) may be placed at other locations within the source code as well as contain different recovery code in order to effect different exception handling strategies. For example, the program may in a first set of exception-related statements attempt to handle a potential floating point overflow exception in the section of the code dealing with the multiplication of two very large numbers. The recovery code for this first set of exception-related statement could choose to set the result to the largest possible floating point number, and continue execution. Within the same program, a second set of exception-related statements may be used to handle null pointer exceptions. Such operations are useful for a wide range of software computer programs, such as data mining applications, database applications, and statistical applications.

[0017] The exception handling functionality may also handle many types of exceptions, such as for example I/O interrupts (e.g., a person hitting control C while the program is executing), null pointer exceptions, overflow errors, or index outside the bounds of an array, etc. Other exception handling may include the recovery code allowing locks to be properly released if the program is involved in a concurrency situation.

[0018] It is noted that the recovery code can perform any actions necessary or useful for handling the exception at hand. For example, the recovery code may allow the executing program to recover from the exception, activate a debugging program to analyze the exception, or terminate the program gracefully. Also, the machine code may be any type of executable code, such as a .EXE file, a dynamic-link library (DLL) file, a self-contained executable program, a program that calls other programs (whether through inter-process, intra-process, and/or network communication mechanisms).

[0019]FIGS. 3 and 4 depict exemplary operational steps for exception handling techniques involving the C exception handling system of FIG. 2. With reference to FIG. 3, start block 200 indicates that process block 202 executes. At process block 202, C source code that contains an ON_EXCEPTION_GOTO( ) and EXCEPTION_LABEL( ) statements is compiled, and process block 204 installs the signal handler.

[0020] At process block 206, the machine code is executed. At process block 208, the machine code hits the ON_EXCEPTION_GOTO( ) statement which causes the address of the recovery code to be recorded. Within the machine code, the code portion that could possibly cause an exception is executed at process block 210. Processing continues on FIG. 4 as indicated by continuation block 212.

[0021] With reference to FIG. 4, decision block 214 examines whether an exception has occurred during execution. If no exception occurred, then execution continues at process block 216 before processing returns from the machine code at process block 224.

[0022] However if an exception had occurred as determined by decision block 214, then the signal handler is invoked at process block 218. At process block 220, the signal handler changes the PC in the exception context to the location recorded by the ON_EXCEPTION_GOTO( ) and returns from the exception. At process block 222, the recovery code at the EXCEPTION_LABEL is executed, and execution continues at process block 216 before processing returns from the machine code at process block 224.

[0023] While examples have been used to disclose the invention, including the best mode, and also to enable any person skilled in the art to make and use the invention, the patentable scope of the invention is defined by the claims, and may include other examples that occur to those skilled in the art. As an example of the wide scope attributable to the system and method, the exception handling operations may be extended to allow exception handling code to be turned off as well as turned back on through compiler options or input configuration data provided during runtime. 

It is claimed as the invention:
 1. A computer-implemented method for handling run-time exceptions, comprising the steps of: (a) receiving source code that includes higher order computer language statements, wherein the statements include an exception branching statement and an exception catching statement; (b) compiling the received source code into machine code and storing the machine code in a non-volatile storage medium; (c) executing the machine code, wherein upon an exception occurring, execution of the executing machine code branches to the exception catching statement in accordance with the exception branching statement.
 2. The method of claim 1 wherein upon an exception happening, an exception signal handler allows execution to resume at recovery code associated with the exception catching statement.
 3. The method of claim 2 wherein the exception signal handler allows execution to resume at the recovery code by placing the value stored from the exception branching statement into a PC (program counter) slot of an exception context structure that was passed to the exception signal handler.
 4. The method of claim 3 wherein the exception branching statement includes ON_EXCEPTION_GOTO statement means.
 5. The method of claim 4 wherein the exception catching statement includes EXCEPTION_LABEL statement means.
 6. The method of claim 4 wherein the ON_EXCEPTION_GOTO( ) statement means records location of the recovery code.
 7. The method of claim 1 wherein the computer program comprises a data mining application.
 8. The method of claim 1 wherein the computer program,comprises a database application.
 9. The method of claim 1 wherein the computer program comprises a statistical application.
 10. The method of claim 1 wherein use of the exception branching statement reduces continually saving the context of the executing machine code when trapping for exceptions.
 11. The method of claim 1 wherein use of the exception branching statement substantially eliminates continually saving the context of the executing machine code when trapping for exceptions.
 12. The method of claim 1 wherein use of the exception branching statement eliminates continually saving the context of the executing machine code when trapping for exceptions.
 13. The method of claim 1 wherein machine code is computer machine readable code.
 14. The method of claim 13 wherein the machine code comprises physical memory addresses.
 15. A compiler stored on a computer readable media, the compiler comprising program code for carrying out steps (a) and (b) of the method according to claim
 1. 16. Computer software stored on a computer readable media, the computer software comprising program code for carrying out step (c) of the method according to claim
 1. 17. The method of claim 1 wherein the source code comprises a first set of branching and catching statements and a second set of branching and catching statements, wherein the first set is directed to handling a first type of exception and the second set is directed to handling a second type of exception.
 18. A computer-implemented system for handling run-time exceptions, comprising: means for compiling source code into machine code and storing the machine code in a non-volatile storage medium, wherein the source code includes higher order computer language statements, wherein the statements include an exception branching statement and an exception catching statement; and means for branching to the exception catching statement in accordance with the exception branching statement upon an exception occurring during execution of the machine code.
 19. A computer-implemented apparatus for handling run-time exceptions of machine code, wherein the machine code was compiled from source code and stored on a non-volatile storage device, wherein the source code includes higher order computer language statements, wherein the statements include an exception branching statement and an exception catching statement, said apparatus comprising: an exception signal handling means for allowing execution to resume at recovery code associated with the exception catching statement. means for branching to the exception catching statement in accordance with the exception branching statement upon an exception occurring during execution of the machine code.
 20. A computer-implemented apparatus for handling run-time exceptions, comprising a compiler that compiles source code into machine code and stores the machine code in a non-volatile storage medium, wherein the source code includes higher order computer language statements, wherein the statements include an exception branching statement and an exception catching statement, wherein the machine code that is generated by the compiler is to include an exception signal handler that allows execution to resume at recovery code associated with the exception catching statement upon occurrence of a runtime exception. 